<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    //两个最大负数 和最大正数
    //三个最大正数
    function fn(nums) {
        let min1 = Infinity, min2 = Infinity
        let max1 = -Infinity, max2 = -Infinity, max3 = -Infinity
        for (let num of nums) {
            if (num < min1) {
                min2 = min1
                min1 = num
            } else if (num < min2) {
                min2 = num
            }
            if (num > max1) {
                max3 = max2
                max2 = max1
                max1 = num
            } else if (num > max2) {
                max3 = max2
                max2 = num
            } else if (num > max3) {
                max3 = num
            }
        }
        let a = {
            value: [min1, min2, max1].reduce((cur, pre) => pre * cur),
            arr: [min1, min2, max1]
        }
        let b = {
            value: [max1, max2, max3].reduce((cur, pre) => pre * cur),
            arr: [max1, max2, max3]
        }

        if (a.value > b.value) {
            return a.arr
        } else {
            return b.arr
        }

    }
   console.log( fn([1, 2, -31, -10, -9, 3, 5, -24]));
   
</script>

</html>